package com.chat.admin.controller;


import com.chat.admin.domain.DTO.ReleaseVersionDTO;
import com.chat.admin.domain.DTO.VersionDTO;
import com.chat.admin.domain.VO.VersionVO;
import com.chat.admin.service.IVersionService;
import com.chat.common.form.ListForm;
import com.chat.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 版本管理
 * @author weikjie
 * @since 2024-05-23
 */
@RestController
@Validated
@RequestMapping("/admin/version")
public class VersionController {

    @Autowired
    IVersionService iVersionService;

    /**
     * 上传版本
     * @param file
     * @param releaseVersionDTO
     * @return
     * @throws IOException
     */
    @PostMapping("/upload")
    public R uploadNews(@RequestParam("file") MultipartFile file,@Validated @ModelAttribute ReleaseVersionDTO releaseVersionDTO) throws IOException {
        return iVersionService.releaseVersion(releaseVersionDTO,file);
    }

    /**
     * 获取版本列表
     * @param versionDTO
     * @return
     */
    @PostMapping("/list")
    public R<ListForm<VersionVO>> getVersionsList(@RequestBody VersionDTO versionDTO) {
        return R.succeed(iVersionService.getVersionsList(versionDTO));
    }

    /**
     * 获取版本号列表
     * @return
     */
    @GetMapping("/list/version_numbers")
    public R<List<String>> getVersionNumbers(){
        return R.succeed(iVersionService.getVersionNumbers());
    }

}
